I am trying to read an array from a include file and then load the array to a skiplist. I can read the file but don't know how to loop thru the array from a inc file. |
Re: How to read an array from a include file
Let's not confuse a native "array" (lower case "a") which can be applied to any data type
-Louie |
Re: How to read an array from a include file Got it!. I accidently typed the word "array" in the attached sample code. but that was not my question... But I just want to know how to loop thru an array by reading that array from a .inc file. (I know how to loop thru any string array if it is in the code but in a .inc file) so far I know how to read the file... string filepath = "\\c:\\temp\\file.inc" string gatedate = "\\c:\\temp\\date.inc" .... Stream input = read filepath Stream input1 = read gatedate string MstrGtslst[]={"A","B","C"} //this contains in the file.inc string gatedate[]={"3/3/12","6/4/13","7/8/14"} //this contains in the date.inc Skip SKgatedates=createstring() i = 0 for (i=0; i<(sizeof(MstrGtslst)); i++){ put(SKgatedates, MstrGtslst[i] , gatedate[i]) } Now i cannot loop thru the MstrGtslst[] The sample code i have attached is giving me an error message that MstrGtslst and gatedate are undeclare...but they declared in the .inc file My end goal is to read two arrays from two different files and load each item into a skiplist as a key and a value. Thanks, FZ |
Re: How to read an array from a include file faisal.zahidi@boeing.com - Fri Aug 10 17:47:47 EDT 2012
Well if the include file is syntactically correct and parsable on its own, you can use an eval_ trick to read the elements. But you should test this well. The strings of the DXL file could be freed when returning to the original context, so if you get crashes then you need to feed them to a buffer instead or something. Regards, Mathias
// put your include in the code
string sCode = "
string arTest[] = {\"This\", \"is\", \"fun!\"}
int arTest2[] = {7,8,9}
"
Skip readArrayFromInclude (string sInclude, string sArrayName, string sArrayType) {
Skip skResult = create()
// This code will marshall the array values to the skip list outside the eval_ context
string sSkipCode = sInclude "
Skip sk = addr_ " ((addr_ skResult) int) "
int i; for (i = 0; i < sizeof " sArrayName "; i++) put(sk, i, " sArrayName "[i])
"
// print sSkipCode
eval_ sSkipCode
return skResult
}
Skip sk1 = readArrayFromInclude (sCode, "arTest", "string")
Skip sk2 = readArrayFromInclude (sCode, "arTest2", "int")
print "String values: "
string sValue; for sValue in sk1 do print sValue " "
print "\n"
print "Int values: "
int iValue; for iValue in sk2 do print iValue " "
print "\n"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: How to read an array from a include file faisal.zahidi@boeing.com - Fri Aug 10 17:47:47 EDT 2012
Your code right now opens the file and gets a Stream handle, but does not read it. It does not make sense to me to read that line, parse it, find the 3 values, and store them in a Skip. As for Mathias' solution, I think your main code will need this:
-Louie |
Re: How to read an array from a include file llandale - Sat Aug 11 12:02:06 EDT 2012
Your code right now opens the file and gets a Stream handle, but does not read it. It does not make sense to me to read that line, parse it, find the 3 values, and store them in a Skip. As for Mathias' solution, I think your main code will need this:
-Louie I am completely lost in the Mathias' code because... the contents of the file.inc is not a single line (more than 3 lines and 50 values) and the two arrays are in two different file1.inc and file2.inc files (array sizes are same). And I want to load the first array data as a key and the second array data as a value in the same skiplist. And the name files are variables. "\\sw\temp\file1.inc" and "\\sw\temp\file1.inc" (files reside on the share drive). if needed, I have the flexability to change the contain format from •string MstrGtslst[]={"A","B","C".......} //file1 values to {"A","B","C"............} ONLY •string datelst[]={"06/23/2011","06/23/2011","07/11/2013".....} //file2 values to {"06/23/2011","06/23/2011","07/11/2013".....} Any suggestion is appreciated. FZ |
Re: How to read an array from a include file faisal.zahidi@boeing.com - Mon Aug 13 12:00:00 EDT 2012
As for writing a CSV parser, I'm not going there. -Louie |
Re: How to read an array from a include file llandale - Mon Aug 13 13:12:26 EDT 2012
As for writing a CSV parser, I'm not going there. -Louie ... but he's only made one mistake ...
string sCode = "#include <myFile.inc>\n"
string sCode = "#include <">\n"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: How to read an array from a include file Mathias Mamsch - Mon Aug 13 16:27:07 EDT 2012 ... but he's only made one mistake ...
string sCode = "#include <myFile.inc>\n"
string sCode = "#include <">\n"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
The include file is on the following location c:\temp\myfile.inc And I edit your code to string sCode = "#include <c:\temp\myFile.inc>\n" And got the following error. -E- DXL: <Line:2> badly formed token ("#include) -E- DXL: <Line:2> incorrect argument for (<_) -E- DXL: <Line:2> undeclared variable (c) what I am doing wrong.... fz |
Re: How to read an array from a include file faisal.zahidi@boeing.com - Mon Aug 13 19:23:58 EDT 2012
Well this is a parser error, which should hint you that your syntax is wrong. You need to escape backslashes or use forward slashes: string sCode = "#include <c:\\temp\\myFile.inc>\n"
string sCode = "#include <c:/temp/myFile.inc>\n"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: How to read an array from a include file Mathias Mamsch - Tue Aug 14 08:42:10 EDT 2012
Well this is a parser error, which should hint you that your syntax is wrong. You need to escape backslashes or use forward slashes: string sCode = "#include <c:\\temp\\myFile.inc>\n"
string sCode = "#include <c:/temp/myFile.inc>\n"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Your code works for two separate skiplists. My end goal is to load both data to a single skiplist as a key value and data. My approach is as follows: string sCode1 = "#include <//sw/sb-data1/ent-doors-sw-dxl/projectaddins/ELS-Standard/include/MEXSAT/GATES.inc>\n" string sCode2 = "#include <//sw/sb-data1/ent-doors-sw-dxl/projectaddins/ELS-Standard/include/MEXSAT/GATE_DATE.inc>\n" Skip readArrayFromIncludeGates (string sInclude, string sArrayName, string sArrayType,string sInclude1, string sArrayName1, string sArrayType1) { Skip skResult = create() // This code will marshall the array values to the skip list outside the eval_ context string sSkipCode = sInclude " Skip sk = addr_ " ((addr_ skResult) int) " int i; for (i = 0; i < sizeof " sArrayName "; i++) put(sk, "sArrayName "[i], " sArrayName1 "[i]) " // print sSkipCode eval_ sSkipCode return skResult } Skip sk1 = readArrayFromIncludeGates (sCode1, "GATES", "string",sCode2, "GATE_DATE","string") print "String values: " string sValue; for sValue in sk1 do print sValue " " print "\n" I believe that the second file is not accessable in the above approach. I am getting the following error message. what I am doing wrong. -E- DXL: <Line:4> incorrect arguments for ([) -E- DXL: <Line:4> incorrect arguments for (for) -E- DXL: <Line:4> incorrect arguments for function (put) -E- DXL: <Line:4> undeclared variable (GATE_DATE) |
Re: How to read an array from a include file Mathias Mamsch - Mon Aug 13 16:27:07 EDT 2012 ... but he's only made one mistake ...
string sCode = "#include <myFile.inc>\n"
string sCode = "#include <">\n"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: How to read an array from a include file faisal.zahidi@boeing.com - Tue Aug 14 13:49:00 EDT 2012
Use the original code to read the values in two different skips. Then intermingle them using the following code:
string sGateVal, sDateVal;
Skip result = createString()
Skip skGates = readArrayFromInclude ("#include <...GATE_DATE.inc>\n", "GATES", "string")
Skip skDates = readArrayFromInclude ("#include <...GATES.inc>\n", "GATE_DATE", "string")
// iterate through gate skip
for sGateVal in skGates do {
// get index in skip
int iKey = (key skGates) int;
// find date value in other skip and put to result
if (find (skDates, iKey, sDateVal)) put (result, sDateVal "", sGateVal "") // make a copy of the strings here to be sure they stay alive ;-)
}
delete skGates; skGates = null
delete skDates; skDates = null
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: How to read an array from a include file |